// pages/findAll/findAll.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 0,
    time: "",
    subtract: 0,
    sex: '保密',
    userPlace: "",
    userIntroduce:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: 'http://192.168.0.26:8081/user/getUserByCode',
      method: 'post',
      data: {
        userCode: wx.getStorageSync('userCode'),
      },
      success: (res) => {
        var myDate = new Date();
        let arr = res.data.data
        let x = arr.createTime.split(" ")[0]
        let oldyear = arr.createTime.split("-")[0]
        let year = myDate.getFullYear()
        let subtract = year - oldyear
        if (arr.userGender == 2) {
          this.setData({
            sex: "女"
          })
        } else if (arr.userGender == 1) {
          this.setData({
            sex: "男"
          })
        } else {
          this.setData({
            sex: "保密"
          })
        }
        if(arr.userIntroduce==""||arr.userIntroduce==null){
          this.setData({
            userIntroduce:"还没有填写个人介绍"
          })
        }else{
          this.setData({
          userIntroduce:arr.userIntroduce
          })
        }

        if(arr.userPlace!=""&&arr.userPlace!=null){
          this.setData({
          userPlace: arr.userPlace,
          })
        }else{
          this.setData({
            userPlace:"未填写"
          })
        }

        this.setData({
          time: x,
          subtract: subtract,
        })
        console.log(this.data.time);
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})